﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PMS.Utils;
using PMS.Win;

namespace PMS
{
    public partial class RegisterForm : FormPopupBase
    {
        RegisterInfo info;
        Register register = new Register();
        public RegisterForm()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                info = new RegisterInfo();
                info.CompanyName = txtCompanyName.Text;
                info.Fullname = txtFullName.Text;
                info.Key = txtKey.Text;
                if (Register.IsValidKey(info.Key))
                {
                    Register.WriteRegisterInfoToFile(info);
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Invalid Key!");
                } 
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}
